"""
@Uses: This file is fill migration table from 150 sites to 41 (technichal sites)
"""

import MySQLdb
import csv 


#"""
tech_site_name = "41_sites_name"
database = "isec2014"
user = "root"
password="123"
port=3306
table = "all_from_migration_aug13"
insert_table = "124_41_site_from_migration_aug13"
file_path = "D:\Research\ISEC-2014\data\matrix1_q36_150_41.csv"
"""
tech_site_name = "41_sites_name"
database = "sangeeta"
user = "sangeetal"
password="sangeetal"
port=3307
table = "all_from_migration_aug13"
insert_table = "124_41_site_from_migration_aug13"
file_path = "E:\sangeeta\matrix1_q36_150_41.csv"
#"""


db1= MySQLdb.connect(host="localhost", user=user, passwd=password,db=database, port=port)
select_cursor = db1.cursor() 
insert_cursor = db1.cursor() 
#s2_cursor = db1.cursor() 


fo = open(file_path, 'wb')
filewriter = csv.writer(fo, delimiter=',', quotechar=' ', quoting=csv.QUOTE_MINIMAL)


file  = open (tech_site_name)
tech_sites = list()
for f in file:
    tech_sites.append(f.strip())
    
query = "select * from "+table+" where migrated in "+ (str)(tech_sites)
query = query.replace("[", "(")
query = query.replace("]", ")")
print query
select_cursor.execute(query)   


migration_data = select_cursor.fetchall()
count = 0
for row in migration_data:
    #print row
    insert_q = "insert into `"+insert_table+"` values("+(str)(row[0])+",'"+row[1]+"','"+row[2]+"')"
    #print insert_q
    insert_cursor.execute(insert_q)
    #break
    count = count+1
    print count

db1.commit()

file.close()    